package TimerTask;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 定时任务学习
 */
public class TimerTaskTest {

    public static void main(String[] args) {

        TimerTask repeatedTask = new TimerTask() {
            @Override
            public void run() {
                System.out.println("任务repeatedTask开始执行");
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("任务repeatedTask执行完毕");
            }
        };

        ScheduledExecutorService executor = Executors.newScheduledThreadPool(10);
        executor.scheduleAtFixedRate(repeatedTask,3000,5000, TimeUnit.MILLISECONDS);

    }


}
